#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>  // 多路复用 I/O

#include <arpa/inet.h>

#include <netinet/in.h>
#include <netinet/ip.h>

#include <iostream>

#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>


#include <sys/stat.h>  // posix: file info

#include <time.h>

#include <thread>
#include <math.h>

#include <map>
#include <vector>
int isRemote(const char *str){
    return strchr(str,':') || strchr(str, '@');
}

void GetParam(char *_str, char *user, char *ip, char *path){
        char *index = _str;
        char *at = strchr(index,'@');
        char *address = strchr(index,':');

        int len = strlen(index);
        strncpy(user, index, at - index); at++;
        strncpy(ip, at, address - at); address ++;
        strcpy(path, address);
}
int main(int argc , char *argv[]) {

    char user[16];
    char ip[16];
    char remote_file[127];

    char local_file[127];

    int op_mode = 0;

    bzero(user, sizeof(user));
    bzero(ip, sizeof(ip));
    bzero(remote_file, sizeof(remote_file));
    bzero(local_file, sizeof(local_file));

    if(argc == 3){
        if(isRemote(argv[1]) && !(isRemote(argv[2]))){
            GetParam(argv[1], user, ip, remote_file);
            strcpy(local_file, argv[2]);
            op_mode = 1;
        }
        if( !(isRemote(argv[1])) && isRemote(argv[2])){
            strcpy(local_file, argv[1]);
            GetParam(argv[2], user, ip, remote_file);
            op_mode = 2;
        } 
        
    }

    printf("%s@%s:%s\n%s\n", user, ip, remote_file, local_file);

    return 0;
}


